﻿using WeDonekRpc.HttpApiGateway;
using WeDonekRpc.HttpApiGateway.Model;
using WeDonekRpc.Client;
using WeDonekRpc.Helper.Validate;
using RpcStore.RemoteModel.Transmit.Model;
using Store.Gatewary.Modular.Interface;

namespace Store.Gatewary.Modular.Api
{
    /// <summary>
    /// 服务节点负载均衡管理
    /// </summary>
    internal class TransmitApi : ApiController
    {
        private readonly ITransmitService _Service;
        public TransmitApi (ITransmitService service)
        {
            this._Service = service;
        }
        /// <summary>
        /// 设置负载均衡项
        /// </summary>
        /// <param name="datum">负载均衡方案</param>
        /// <returns></returns>
        public void Set ([NullValidate("rpc.store.transmit.datum.null")] LongParam<TransmitConfig[]> datum)
        {
            this._Service.Set(datum.Id, datum.Value);
        }
        /// <summary>
        /// 添加负载均衡项
        /// </summary>
        /// <param name="datum"></param>
        public void Add ([NullValidate("rpc.store.transmit.datum.null")] TransmitAdd datum)
        {
            this._Service.Add(datum);
        }
        /// <summary>
        /// 删除负载均衡项
        /// </summary>
        /// <param name="id">数据ID</param>
        public void Delete ([NumValidate("rpc.store.transmit.id.error", 1)] long id)
        {
            this._Service.Delete(id);
        }

        /// <summary>
        /// 获取负载均衡项信息
        /// </summary>
        /// <param name="id">数据ID</param>
        /// <returns></returns>
        public TransmitConfig[] Get ([NumValidate("rpc.store.transmit.id.error", 1)] long id)
        {
            return this._Service.Get(id);
        }

        /// <summary>
        /// 查询服务节点负载均衡项
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        public PagingResult<TransmitServer> Query ([NullValidate("rpc.store.transmit.param.null")] PagingParam<TransmitQuery> param)
        {
            return this._Service.Query(param.Query, param);
        }

    }
}
